home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2006 May
/
PCWMAY06.iso
/
Software
/
Resources
/
HTMLGate 12.2.1B
/
htmlgate.exe
/
{app}
/
Cookies
/
cookie12.txt
< prev
next >
Wrap
Text File
|
2002-09-26
|
3KB
|
72 lines
<SCRIPT LANGUAGE="JavaScript">
<!-- Hide from older browsers
var cookieObject = document.cookie.split("; "); // break cookie into array of cookieObject
function getCookie(name) {
for (i=0; i < cookieObject.length; i++) {
nextbite = cookieObject[i].split("="); // break into name and value
if (nextbite[0] == name) // if name matches
return unescape(nextbite[1]); // return value
}
return null; // if no match return null
}
var today = new Date();
var expiry = new Date(today.getTime() + 28 * 24 * 60 * 60 * 1000); // plus 28 days
function setCookie(name, value) { // use: setCookie("name", value);
if (value != null && value != "")
document.cookie=name + "=" + escape(value) + "; expires=" + expiry.toGMTString();
cookieObject = document.cookie.split("; "); // update cookie cookieObject
}
var userData = getCookie("userData") || "white!Visitor!1"; // retrieve values or use default
var data = userData.split("!"); // convert cookie value to array
// Stop hiding -->
</SCRIPT>
<BODY BGCOLOR="white" TEXT="black" LINK="#003333" ALINK="#ffff00" VLINK="#336633"
ONLOAD="
for (i=0; i < 3; i++)
if (data[i] != null) document.forms[0].elements[i].value = data[i];
if (data[0] != null)
document.bgColor=data[0]; // set background colour
">
<BLOCKQUOTE>
<FORM NAME="cookieTest" METHOD="post">
<DIV ALIGN="center"><CENTER><TABLE BORDER="0" BGCOLOR="#000000" CELLPADDING="5"
CELLSPACING="0">
<TR>
<TH ALIGN="left"><FONT FACE="Verdana" SIZE="2" COLOR="#FFFFFF">Background: </FONT></TH>
<TD><FONT FACE="Verdana" SIZE="2" COLOR="#FFFFFF"><INPUT NAME="data0" TYPE="text"
VALUE="white" SIZE="30"></FONT></TD>
</TR>
<TR>
<TH ALIGN="left"><FONT FACE="Verdana" SIZE="2" COLOR="#FFFFFF">Your Name: </FONT></TH>
<TD><FONT FACE="Verdana" SIZE="2" COLOR="#FFFFFF"><INPUT NAME="data1" TYPE="text"
VALUE="Traveller" SIZE="30"></FONT></TD>
</TR>
<TR>
<TH ALIGN="left"><FONT FACE="Verdana" SIZE="2" COLOR="#FFFFFF">Head Count: </FONT></TH>
<TD><FONT FACE="Verdana" SIZE="2" COLOR="#FFFFFF"><INPUT NAME="data2" TYPE="text"
VALUE="1" SIZE="30"></FONT></TD>
</TR>
<TR BGCOLOR="#003333">
<TD ALIGN="right" COLSPAN="2" BGCOLOR="#000000"><INPUT TYPE="button" VALUE="Execute"
ONCLICK="
with (this.form) {
data[0] = data0.value; // if you want to add another variable
data[1] = data1.value; // just use data[3] or higher
data[2] = data2.value; // you can do this anywhere on the page.
}
setCookie('userData', data.join('!')); // cookie will store any length array
history.go(0);"></TD>
</TR>
</TABLE>
</CENTER></DIV>
</FORM>
</BLOCKQUOTE>